package com.threegroup.android3grouppersonality.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.threegroup.android3grouppersonality.R;
import com.threegroup.android3grouppersonality.ui.activity.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

public class NearbyFragment extends Fragment implements View.OnClickListener{
    private ListView lvnearbyNews;
    private Banner banner=null;
    private List<String> img = new ArrayList<>();
    private List<String> imgtitles = new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =inflater.inflate(R.layout.fragment_nearby, container, false);
        lvnearbyNews=view.findViewById(R.id.lvnearbyNews);
        banner= (Banner)view.findViewById(R.id.bannervp);
        return view;
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initData();
        initview();
    }

    private void initview() {


        banner.setImageLoader(new GlideImageLoader());
        banner.setIndicatorGravity(BannerConfig.RIGHT);//圆点的位置

        banner.setImages(img).//加载的图片
                setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE).setBannerTitles(imgtitles)
                .setDelayTime(2000).start();

        //设置点击事件
        banner.setOnBannerListener(new OnBannerListener(){
            @Override
            public void OnBannerClick(int position) {
                switch (position){
                    case 0:
                        Toast.makeText(getActivity(),"111",Toast.LENGTH_LONG).show();
                        break;
                    case 1:
                        Toast.makeText(getActivity(),"222",Toast.LENGTH_LONG).show();
                        break;
                    case 2:
                        Toast.makeText(getActivity(),"333",Toast.LENGTH_LONG).show();
                        break;
                    case 3:
                        Toast.makeText(getActivity(),"444",Toast.LENGTH_LONG).show();
                        break;
                }

            }


        });

    }



    private void initData() {
        //添加图片
       if(img.size()>3){
           return;
       }
        img.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1089399937,1684001946&fm=23&gp=0.jpg");
        img.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=787324823,4149955059&fm=23&gp=0.jpg");
        img.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3514483810,1208920576&fm=23&gp=0.jpg");
        img.add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1917280427,3920336884&fm=23&gp=0.jpg");
        //添加图片标题
        imgtitles.add("图片1");
        imgtitles.add("图片2");
        imgtitles.add("图片3");
        imgtitles.add("图片4");


    }

    @Override
    public void onClick(View view) {

    }
}
